package com.example.testanimation.truditionnal.d3;

import java.io.FileDescriptor;
import java.io.PrintWriter;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.testanimation.R;
import com.example.testanimation.truditionnal.Animation_LayoutAnimation_Activity;
import com.lenovo.nova.util.DebugUtil;
import com.lenovo.nova.util.DebugUtil.OnDumpExecuteListener;

public class Animation_3DRotateAnimation_Activity extends Animation_LayoutAnimation_Activity {

	private ListView mList;

	private ViewGroup viewGroup;
	private ImageView mImgView;
	private Rotate3dAnimation animation;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rotate_3d_animation);
		viewGroup = (ViewGroup) findViewById(R.id.id_flayout_mainContainer);
		mList = (ListView) findViewById(R.id.id_lstview_animation);
		mList.setScrollbarFadingEnabled(false);
		mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] {//
				"111111111111111111111111111111111111111111111111",//
						"111111111111111111111111111111111111111111111111",//
						"111111111111111111111111111111111111111111111111", //
						"111111111111111111111111111111111111111111111111",//
						"111111111111111111111111111111111111111111111111", //
						"111111111111111111111111111111111111111111111111", //
						"111111111111111111111111111111111111111111111111",//

				}));

		mImgView = (ImageView) findViewById(R.id.id_imgview_showDetail);

		
		mList.setOnItemClickListener(new OnItemClickListener() {


			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				animation = new 
						Rotate3dAnimation(
								0f,
								180, 
								(float) viewGroup.getWidth() / 2, 
								(float) viewGroup.getHeight() / 2,
								310f,
								true);
				animation.setDuration(10000);
				animation.setRepeatCount(-1);
				animation.setAnimationListener(new AnimationListener() {
					@Override
					public void onAnimationStart(Animation animation) {

					}

					@Override
					public void onAnimationRepeat(Animation animation) {

					}

					@Override
					public void onAnimationEnd(Animation animation) {/*
						mImgView.setVisibility(View.VISIBLE);
						mList.setVisibility(View.GONE);
//						MyAnimation animationForImage = new MyAnimation(90f, 180f, (float) viewGroup.getWidth() / 2, (float) viewGroup.getHeight() / 2);
						Rotate3dAnimation animationForImage = new Rotate3dAnimation(
								90f, 
								180f, 
								(float) viewGroup.getWidth() / 2,
								(float) viewGroup.getHeight() / 2, 
								310, 
								false);
						animation.setDuration(1000);
						viewGroup.startAnimation(animationForImage);
					*/}
				});
				viewGroup.startAnimation(animation);
			}
		});

		
		DebugUtil.getInstance(this).setOnDumpExecuteListener(new OnDumpExecuteListener() {



            @Override
            public boolean onDumpExecute(DebugUtil util, String prefix, FileDescriptor fd, PrintWriter writer, String[] args, String cmdValue) {

				
				if(cmdValue.equals("setDepthZ")){
					animation.setDepthZ(util.nextCmdValueAsInt());
				}
				
				if(cmdValue.equals("setReverse")){
					animation.setReverse(util.nextCmdValueAsInt() == 1);
				}
				
				return true;
			}
		}).addCustomCmd("setDepthZ","setReverse");
		
		;
		
	}

}
